<template>
  <div>
    <!-- 搜索框 -->
    <TopFilter :list="topFilterList" :cols="4" :labelWidth="90" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="wxGwTable"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isExportExcel="false"
      exportFileName="工位定义导出表.xlsx"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新建</el-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <BrandModal :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { partModelGroupSql, selectWorkGroupDicts } from '@/api/repair/repairBusiness/LocationDefined';
import BrandModal from './brandModal';

export default {
  name: 'Brand',
  components: {
    BrandModal
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', edit: '编辑', show: '显示' };
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: {},
      visible: false,
      dialogTitle: '',
      fetchApi: partModelGroupSql,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {}
    };
  },
  created() {
    // this.selectWorkGroupDicts();
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    // 搜索
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '工位代码',
          fieldName: 'labourPositionCode',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '工位名称',
          fieldName: 'labourPositionName',
          placeholder: '请输入...'
        },
        {
          type: 'SELECT',
          label: '工位类别',
          fieldName: 'labourPositionType',
          itemList: this.createDictList('8041'),
          placeholder: '请输入...'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 60,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工位代码',
          dataIndex: 'labourPositionCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '工位名称',
          dataIndex: 'labourPositionName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '工位类别',
          dataIndex: 'labourPositionType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8041'),
          dictItems: this.createDictList('8041')
        },
        {
          title: '班组名称',
          dataIndex: 'workgroupName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        // {
        //   title: '是否多车工位',
        //   dataIndex: 'isManyPosition',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1004'),
        //    dictItems: this.createDictList('1004'),
        //   disabled: true,
        //   editable: true,
        //   defaultEditable: true,
        //   editType: 'checkbox',
        //   editItems: [
        //     { text: '', trueValue: 10041001 },
        //     { text: '', falseValue: 10041002 }
        //   ]
        // },
        // {
        //   title: '工位容量',
        //   dataIndex: 'repairCapability',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number'
        // },
        // {
        //   title: '技师代码',
        //   dataIndex: 'TECHNICIAN',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '技师名称',
        //   dataIndex: 'TECHNICIAN_NAME',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '工位状态',
          dataIndex: 'STATUS',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '启用', value: 10041002 },
            { text: '停用', value: 10041001 }
          ],
          dictItems: [
            { text: '启用', value: 10041002 },
            { text: '停用', value: 10041001 }
          ]
        }
        // {
        //   title: '停用日期',
        //   dataIndex: 'DISABLE_DATE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'date-range'
        // }
      ];
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}维修工位`;
      this.visible = true;
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
